package com.ruoyi.amuse.likes.controller;

import com.ruoyi.amuse.likes.domain.PostLikes;
import com.ruoyi.amuse.likes.service.IPostLikesService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 点赞管理Controller
 * 
 * @author juwujie
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/likes/likes")
public class PostLikesController extends BaseController
{
    @Autowired
    private IPostLikesService postLikesService;

    /**
     * 查询点赞管理列表
     */
    @RequiresPermissions("likes:likes:list")
    @GetMapping("/list")
    public TableDataInfo list(PostLikes postLikes)
    {
        startPage();
        List<PostLikes> list = postLikesService.selectPostLikesList(postLikes);
        return getDataTable(list);
    }

    /**
     * 导出点赞管理列表
     */
    @RequiresPermissions("likes:likes:export")
    @Log(title = "点赞管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostLikes postLikes)
    {
        List<PostLikes> list = postLikesService.selectPostLikesList(postLikes);
        ExcelUtil<PostLikes> util = new ExcelUtil<PostLikes>(PostLikes.class);
        util.exportExcel(response, list, "点赞管理数据");
    }

    /**
     * 获取点赞管理详细信息
     */
    @RequiresPermissions("likes:likes:query")
    @GetMapping(value = "/{likeId}")
    public AjaxResult getInfo(@PathVariable("likeId") Long likeId)
    {
        return success(postLikesService.selectPostLikesByLikeId(likeId));
    }

    /**
     * 新增点赞管理
     */
    @RequiresPermissions("likes:likes:add")
    @Log(title = "点赞管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostLikes postLikes)
    {
        return toAjax(postLikesService.insertPostLikes(postLikes));
    }

    /**
     * 修改点赞管理
     */
    @RequiresPermissions("likes:likes:edit")
    @Log(title = "点赞管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostLikes postLikes)
    {
        return toAjax(postLikesService.updatePostLikes(postLikes));
    }

    /**
     * 删除点赞管理
     */
    @RequiresPermissions("likes:likes:remove")
    @Log(title = "点赞管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeIds}")
    public AjaxResult remove(@PathVariable Long[] likeIds)
    {
        return toAjax(postLikesService.deletePostLikesByLikeIds(likeIds));
    }
}
